package com.hpu.parser;

import com.hpu.bean.Lecture;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class LectureParser{

	public List<Lecture> parse(String parseString) {
		List<Lecture> lectures=new ArrayList<>();
		try {
			JSONArray array=new JSONArray(parseString);
			for(int i=0;i<array.length();i++){
				JSONObject object=array.getJSONObject(i);
				String id=object.getString("id");
				String name=object.getString("name");
				String who=object.getString("who");
				String time=object.getString("time");
				String place=object.getString("place");
				String content=object.getString("content");
				Lecture lecture=new Lecture(id,name,who,time,place,content);
				lectures.add(lecture);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return lectures;
	}
}
